﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS2Lua
{
    public class Il2LuaContext
    {

    }
    public class TypeManager
    {
        public const string NsIl2LuaRT = "il2luart";

        /// <summary>
        /// 当前环境
        /// </summary>
        public readonly Il2LuaContext Context;
    }
    public class GeneratorContext
    {
        //public readonly TypeManager ;
        public string GetTypeName(LuaTypeDefinition type, bool expandEnum)
        {
            if (type == null)
                return "il2cppDummy";
            if (expandEnum)
            {
                if (type.IsEnumType)
                    return GetTypeName(type.EnumTypeSig);
            }

            string strName = type.GeneratedTypeName;
            if (strName == null)
            {
                strName = type.IsValueType ? "stru_" : "cls_";

                string nameKey = type.GetNameKey();
                if (!type.HasGenArgs && type.Def.DefinitionAssembly.IsCorLib())
                    strName += nameKey;
                else
                    strName += NameHash(nameKey.GetHashCode()) + '_' + GetNameWithGen(type.Def.Name, type.GenArgs);

                type.GeneratedTypeName = strName = GetNotUsedTypeName(EscapeName(strName));
            }

            return strName;
        }
    }
    public class CompileUnit
    {

    }
    public class TypeGenerator
    {
        private readonly GeneratorContext GenContext;
        private readonly LuaTypeDefinition CurrentType;
        public TypeGenerator(GeneratorContext context, LuaTypeDefinition type)
        {
            GenContext = context;
            CurrentType = type;
        }

        public CompileUnit Generate()
        {
            CompileUnit unit = new CompileUnit();
            string strTypeName = GenContext.GetTypeName(CurrentType, false);

        }
    }
}
